﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Utils;
using Settings;
namespace PanasonicWarranty.DAL
{
    public partial class DBpa_Customer
    {
        //// Since this class provides only static methods, make the default constructor private to prevent
        //// instances from being created with "new DBpa_Customer()"
        private DBpa_Customer() { }
        
        public static bool Create(string CustomerPhone, string CustomerName, string Address, bool? Disabled)
		{
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, "sp_pa_Customer_Insert", CustomerPhone, CustomerName, Address, Disabled);
                    return (result > 0);
                }
            }catch(Exception ex){
                throw ex;
            }
		}

		public static bool Update(string CustomerPhone, string CustomerName, string Address, bool? Disabled)
		{
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, "sp_pa_Customer_Update", CustomerPhone, CustomerName, Address, Disabled);
                    return (result > 0);
                }
            }catch(Exception ex){
                throw ex;
            }
		}

		public static bool Delete(string CustomerPhone)
		{
            try
            {
                using (SqlConnection conn = new SqlConnection(CommonSetting.ConnectionString))
                {
                    int result = SqlHelper.ExecuteNonQuery(conn, "sp_pa_Customer_Delete", CustomerPhone);
                    return (result > 0);
                }
            }catch(Exception ex){
                throw ex;
            }
		}

        public static SqlDataReader GetAll()
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, CommandType.StoredProcedure,"sp_pa_Customer_GetByAll");
            }catch(Exception ex){
                throw ex;
            }
        }

        public static SqlDataReader GetByKey(string CustomerPhone)
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, "sp_pa_Customer_GetById", CustomerPhone);
            }catch(Exception ex){
                throw ex;
            }
        }

        public static SqlDataReader GetByTop(string top, string where, string order)
        {
            try
            {
                return SqlHelper.ExecuteReader(CommonSetting.ConnectionString, "sp_pa_Customer_GetByTop", top, where, order);
            }catch(Exception ex){
                throw ex;
            }
        }
	}
}
